package com.example.shirospringboot.controller;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class AppExceptionHandler {
    /**
     * 用来处理密码不正确
     * @return
     */
    @ExceptionHandler(IncorrectCredentialsException.class)
    public ResponseEntity incorrectCredentialsException() {
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("用户名或密码不正确");
        
    }
    
    /**
     * 用来处理其他的认证异常
     * @param e
     * @return
     */
    @ExceptionHandler({AuthenticationException.class})
    public ResponseEntity authenException(Exception e) {
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage());
    }
}
